/*
 * Copyright (c) 2022 Queclink-C-Library
 *
 * This file is subject to the terms and conditions of the MIT License.
 * For details, please see the LICENSE file or visit the MIT website: https://mit-license.org/
 */

#include <stddef.h>
#include <string.h>
#include <stdlib.h>

#include <qlibc/assert.h>

#include "qlibc_log.h"
int quec_atoi(const char *nptr, size_t n)
{
    assert(NULL != nptr);
    assert(0 < n && n < 12);

    char temp[16] = {0};
    if (n > 15)
        n = 15;

    memcpy(temp, nptr, n);

    return atoi(temp);
}

long int quec_strtol(const char *nptr, size_t n, int base)
{
    assert(NULL != nptr);
    assert(0 < n && n < 33);
    assert(base < 33);

    char temp[36] = {0};
    if (n > 35)
        n = 35;

    memcpy(temp, nptr, n);

    return strtol(temp, NULL, base);
}
